package com.leo.ktvplayer.ui.login

import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.View.OnKeyListener
import android.widget.TextView
import com.leo.ktvplayer.R
import com.leo.ktvplayer.base.ActBase
import com.leo.ktvplayer.localcookie.LocalUtils
import com.leo.ktvplayer.localcookie.LocalUtilsByKotlin
import com.leo.ktvplayer.ui.chosetype.ActChoseType
import com.leo.ktvplayer.ui.setting.ManagerDialog
import com.leo.ktvplayer.util.ToastUtil
import kotlinx.android.synthetic.main.activity_login.*
import java.lang.ref.SoftReference

/**
 * Created by LeoLu on 2017/6/9.
 */

class ActLoginKotlin() : ActBase(),View.OnClickListener, View.OnLongClickListener{


    var time : Long = 1L;

    companion object {

    }

    override fun onClick(v: View?) {
        var intent : Intent = Intent();//初始化Intent
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        intent.setClass(this,ActChoseType::class.java);
        startActivity(intent)


    }

    private fun showManagerDialog(){
       var managerDialog : ManagerDialog = ManagerDialog(this,R.style.dialog)
        managerDialog.setOnManagerDialogClickedListener { action, text ->
            when(action){
                ManagerDialog.OnManagerDialogClickedListener.ACTION_POSITIVE ->{
                    if (TextUtils.isEmpty(text)){
                        ToastUtil.show("密码不能为空")
                    } else if (text.equals(LocalUtilsByKotlin.getUser().userpwd)){
                        goSetting()
                        managerDialog.dismiss()
                    }
                }
            }
        }
        managerDialog.show()
    }

    override fun onLongClick(v: View?): Boolean {

        showManagerDialog()
        return false;
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login);
        setupViews()
        openBle()
    }

    private fun setupViews(){
        btn_activity_login_setup.setOnClickListener(this)
        tv_activity_login_title.setOnLongClickListener(this)


    }


}